package com.aba.bms.system;

import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;
 
public class LibraryManagementSystem {
 
    public static void main(String[] args) {
        // 打印欢迎信息
        System.out.println("欢迎使用图书馆管理系统");
 
        // 初始化系统组件
        SystemConfigDao systemConfigDao = new SystemConfigDao();
        UserPermissionDao userPermissionDao = new UserPermissionDao();
        ReportGenerator reportGenerator = new ReportGenerator();
 
        // 启动报表生成定时任务
        reportGenerator.startDailyReportTask();
 
        // 启动用户界面
        try {
			startUserInterface(systemConfigDao, userPermissionDao);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
 
    private static void startUserInterface(SystemConfigDao systemConfigDao, UserPermissionDao userPermissionDao) throws SQLException {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("\n请选择操作：");
            System.out.println("1. 查看系统配置");
            System.out.println("2. 查看用户权限");
            System.out.println("3. 查看借阅统计");
            System.out.println("4. 退出系统");
            System.out.print("请输入选项：");
            
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    viewSystemConfig(systemConfigDao);
                    break;
                case 2:
                    viewUserPermissions(userPermissionDao);
                    break;
                case 3:
                    viewBorrowStatistics();
                    break;
                case 4:
                    System.out.println("感谢使用图书馆管理系统，再见！");
                    scanner.close();
                    System.exit(0);
                    break;
                default:
                    System.out.println("无效选项，请重新输入。");
            }
        }
    }
 
    private static void viewSystemConfig(SystemConfigDao systemConfigDao) throws SQLException {
		// TODO Auto-generated method stub
    	
            System.out.println("\n所有系统配置：");
            List<SystemConfigDao> configs = systemConfigDao.getAllConfigs();
            if (configs.isEmpty()) {
                System.out.println("当前没有系统配置信息。");
            } else {
                for (SystemConfigDao config : configs) {
                    System.out.println("键名: " + config.getConfigKey());
                    System.out.println("值: " + config.getConfigValue(null));
                    System.out.println("描述: " + config.getDescription());
                    System.out.println("------------------------");
                }
            }
        }
	

	private static void viewUserPermissions(UserPermissionDao userPermissionDao) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("\n用户权限管理：");
        try {
            System.out.println("请输入要查看的角色名称：");
            String roleName = scanner.nextLine();
            List<String> permissions = userPermissionDao.getPermissionsByRole(roleName);
            System.out.println("角色 " + roleName + " 的权限：");
            if (permissions.isEmpty()) {
                System.out.println("该角色没有分配权限。");
            } else {
                for (String permission : permissions) {
                    System.out.println("- " + permission);
                }
            }
        } catch (Exception e) {
            System.out.println("获取用户权限时出错: " + e.getMessage());
        }
    }
 
    private static void viewBorrowStatistics() {
        // 示例：显示借阅统计信息
        System.out.println("\n借阅统计信息：");
        System.out.println("这里可以显示借阅统计信息。");
        // 假设有方法获取借阅统计信息
        // 需要实现从数据库中获取统计信息并显示
    }
}
